#ifndef PROCESS_H
#define PROCESS_H
#include <QQmlApplicationEngine>
#include <QRunnable>
#include <QElapsedTimer>
#include <QFuture>
#include <QtConcurrent/QtConcurrent>
#include <QEventLoop>
#include <QMessageBox>
#include "viewer.h"
#include "rosconnector.h"
#include "trajPlanning.h"
#include "vsPhotometric.h"

enum STEP{
    S1,
    S2,
    S3,
    S4,
    S5,
    S6,
    S7,
    S8,
    S9,
    FIN
};

const QMap<int, QVector<std::pair<int, int>>> op2Led{
    {1, {{1, 2}, {1, 3}}},
    {2, {{2, 1}, {2, 2}}},
    {3, {{2, 3}, {2, 4}}},
    {4, {{3, 1}, {3, 2}}},
    {5, {{3, 3}, {3, 4}}},
    {6, {{5, 3}, {5, 4}, {4, 3}, {4, 4}}},
    {7, {{5, 1}, {5, 2}, {4, 1}, {4, 2}}},
    {8, {{6, 3}, {6, 4}}},
    {9, {{6, 1}, {6, 2}}},
    {10, {{1, 1}, {1, 4}}},
};

// 记录当前处理状态
// 分别记录当前操作位id、螺钉id、步骤id
// 注意操作位id范围为[1, 10], 螺钉id起始下标为0, 比方说一号操作位两颗螺钉编号为0和1
struct context{
    int curOpIdx;
    int curScrewIdx;
    STEP curStep;

    context() : curOpIdx(1), curScrewIdx(0), curStep(S1){}
    context(int opIdx, int screwIdx, STEP step) : curOpIdx(opIdx), curScrewIdx(screwIdx), curStep(step){}

    bool isEnd(){
        if(this->curOpIdx == 10 && this->curScrewIdx == op2Led[this->curOpIdx].size() - 1 && this->curStep == FIN){
            return true;
        }
        return false;
    }
};

// 初始化界面控制器Viewer
Viewer* initViewer(QQmlApplicationEngine& engine);

// 自动模式
void processInAutoMode(Viewer* view, context* curContext);

// 手动模式
void processInManualMode(Viewer* view, context* curContext);
#endif // PROCESS_H
